package com.tensquare.sms.listener;

import com.rabbitmq.client.Channel;
import com.tensquare.sms.utiils.SmsUtil;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

@Component
public class SmsListener {

    @Autowired
    private SmsUtil smsUtil;

    @Value("${aliyun.sms.template_code}")
    private String template_code;//模板编号

    @Value("${aliyun.sms.sign_name}")
    private String sign_name;//签名

    /**
     * 发送短信
     *
     * @param message
     */
    @RabbitListener(queues = "sms")
//    @RabbitHandler
    public void sendSms(Map<String, String> message, Message messages, Channel channel) {
        System.out.println("手机号：" + message.get("mobile"));
        System.out.println("验证码：" + message.get("code"));

        smsUtil.sendSms(message.get("mobile"), template_code, sign_name,
                "{\"code\":\"" + message.get("code") + "\"}");

    }

}
